import axios from 'axios';

const request = axios.create({
	baseURL: 'http://39.98.123.211/api',
	timeout: 10000
});

request.interceptors.request.use((config) => {
	config.headers.token = 'token~~~';

	return config;
});

request.interceptors.response.use(
	(response) => {
		if (response.data.code === 200) {
			return response.data.data;
		}

		return Promise.reject(response.data.message);
	},
	(error) => {
		console.log(error);
		return Promise.reject('找不到网络');
	}
);

export default request;
